<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="所属物业" prop="propertyId" v-if="userType!==4 && activeName === '0'">
        <el-select v-model="queryParams.propertyId" placeholder="请选择物业" style="width: 150px;" size="mini">
          <el-option v-for="property in propertyListOptions"
                     :key="property.id"
                     :label="property.propertyName"
                     :value="property.id"/>
        </el-select>
      </el-form-item>

      <el-form-item label="所属小区" prop="id" v-if="userType!==4 && activeName === '0'">
        <el-select v-model="queryParams.id" placeholder="请选择小区" style="width: 150px;" size="mini" filterable clearable>
          <el-option v-for="estate in estateListOptions"
                     :key="estate.id"
                     :label="estate.estateName"
                     :value="estate.id"/>
        </el-select>
      </el-form-item>

      <el-form-item label="支付平台" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付平台" size="mini" clearable>
          <el-option :value="0" label="微信支付"/>
          <el-option :value="1" label="农商银联支付"/>
        </el-select>
      </el-form-item>

      <el-form-item label="查询时间" prop="dateRange">
        <el-date-picker v-model="dateRange" clearable size="mini" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleEstate">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetEstate">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleEstateExport"
        >统计导出</el-button>
      </el-col>
    </el-row>
    <div>
      <el-table v-loading="loading" :data="estateList">
        <el-table-column label="所属物业" align="center" prop="propertyName"/>
        <el-table-column label="所属小区" align="center" prop="estateName"/>
        <el-table-column label="商家服务交易" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.productOrderExcel!=null">{{scope.row.productOrderExcel.totalPrice+'元'}}</div>
            <div v-else>0元</div>
          </template>
        </el-table-column>
        <el-table-column label="物业费交易" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.propertyFeeOrder!=null">{{scope.row.propertyFeeOrder.payMoney+'元'}}</div>
            <div v-else>0元</div>
          </template>
        </el-table-column>

        <el-table-column label="代收电费" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.propertyFeeOrder!=null">{{scope.row.propertyFeeOrder.electricFee+'元'}}</div>
            <div v-else>0元</div>
          </template>
        </el-table-column>

        <el-table-column label="代收水费" align="center" >
          <template slot-scope="scope">
            <div v-if="scope.row.propertyFeeOrder!=null">{{scope.row.propertyFeeOrder.waterFee+'元'}}</div>
            <div v-else>0元</div>
          </template>
        </el-table-column>

        <el-table-column label="供水转换费" align="center" >
          <template slot-scope="scope">
            <div v-if="scope.row.propertyFeeOrder!=null">{{scope.row.propertyFeeOrder.jiaYaFee+'元'}}</div>
            <div v-else>0元</div>
          </template>
        </el-table-column>

        <el-table-column label="垃圾处理费" align="center" >
          <template slot-scope="scope">
            <div v-if="scope.row.propertyFeeOrder!=null">{{scope.row.propertyFeeOrder.trashFee+'元'}}</div>
            <div v-else>0元</div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total >0"
                  :total="total"
                  :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getEstateStatisticsList" />
    </div>

  </div>
</template>

<script>
  import { listPropertyNoPage } from "@/api/module/property/property";
  import { listAllEstate ,listStatistics, exportTotal } from "@/api/module/estate/estate";

  import CountTo from 'vue-count-to';
  import singlePic from '@/components/SingleMaterial';
  import Template from "@/views/module/estate/template";

  export default {
    name: "Property",
    components: {
      Template,
      singlePic, CountTo,
      AreaOptions:() => import('@/components/AreaOptions'),
    },
    data() {
      return {
        activeName:'',
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        dateRange:[],
        // 总条数
        total: 0,
        // 物业公司表格数据
        orderList: [],
        estateList:[],
        //物业公司列表
        propertyListOptions:[],
        //小区列表
        estateListOptions:[],
        // 弹出层标题
        title: "",
        fenRun: 0,
        orderMoneyAll:0,
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          propertyId:undefined,
          id:undefined,
          payType:undefined,
          beginDate:undefined,
          endDate:undefined,
        },
        // 表单参数
        form: {},
        userType:undefined,
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getPropertyList();
      this.getEstateList();
      this.getEstateStatisticsList();
    },
    methods: {
      /** 查询物业公司列表 */
      getEstateStatisticsList() {
        this.loading = true;
        listStatistics(this.queryParams).then(response => {
          this.estateList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getPropertyList() {
        listPropertyNoPage().then(response => {
          this.propertyListOptions = response.data;
        });
      },
      getEstateList() {
        listAllEstate().then(response => {
          this.estateListOptions = response.data;
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length!==1;
        this.multiple = !selection.length
      },
      /** 搜索按钮操作 */
      handleEstate() {
        this.queryParams.pageNum = 1;
        console.log('dateRange',this.dateRange);
        if(this.dateRange !=undefined && this.dateRange.length === 2){
          this.queryParams.beginDate = this.dateRange[0];
          this.queryParams.endDate = this.dateRange[1];
        }
        this.getEstateStatisticsList();
      },
      resetEstate() {
        this.resetForm("queryForm");
        this.handleEstate();
      },
      /** 导出物业统计按钮操作 */
      handleEstateExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有物业小区数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportTotal(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      },
    }
  };
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .panel-group {
    margin-top: 10px;
    .card-panel-col{
      margin-bottom: 10px;
    }
    .card-panel {
      height: 108px;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      cursor: pointer;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);



      .icon-people {
        color: #40c9c6;
      }
      .icon-message {
        color: #36a3f7;
      }
      .icon-money {
        color: #f4516c;
      }
      .icon-shopping {
        color: #34bfa3
      }
      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }
      .card-panel-icon {
        float: left;
        font-size: 48px;
      }
      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        color:white;
        /*margin-left: 0px;*/
        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }
        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }
</style>
